//
//  SearchTypeView.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/5/15.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "SearchTypeView.h"

@implementation SearchTypeView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]) {
        
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]];
        
        UIView *view = [[UIView alloc] initWithFrame:frame];
        view.backgroundColor = [UIColor whiteColor];
        
        for (int i = 0; i<2; i++) {
            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, i*frame.size.height/2., frame.size.width, frame.size.height/2.-.5)];
            [btn setTitle:@[@"商品",@"店铺"][i] forState:UIControlStateNormal];
            btn.titleLabel.font = DEF_FontSize_10;
            btn.backgroundColor = getColor(mainColor);
            btn.tag = 200+i;
            [btn addTarget:self action:@selector(selectEvent:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:btn];
            
            
        }
        
        [self addSubview:view];
    }
    return self;
}

- (void)selectEvent:(UIButton *)sender{
    if (self.typeSelectHandle) {
        self.typeSelectHandle(sender.tag - 200);
    }
    [self dismiss];
}

- (void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}

- (void)dismiss{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
